package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketTopic;
import com.cskaoyan.market.service.AdminTopicService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("admin/topic")
public class AdminTopicController extends HttpServlet {
    @Autowired
    AdminTopicService adminTopicService;

    @GetMapping("list")
    private Object list(String page,String limit,String sort,String order,String title,String subtitle) throws IOException {

        List<MarketTopic> marketTopic = adminTopicService.getList(page,limit,sort,order,title,subtitle);

        return ResponseUtil.okList(marketTopic);
    }


    @PostMapping("batch-delete")
    private Object batchDelete(@RequestBody List list) throws IOException {

        adminTopicService.batchDelete(list);

        return ResponseUtil.ok();
    }

    @PostMapping("delete")
    private Object delete(@RequestBody MarketTopic marketTopic) throws IOException {

        adminTopicService.delete(marketTopic);

        return ResponseUtil.ok();
    }

}
